package com.gxc.utils;

import org.apache.commons.beanutils.BeanUtils;

import java.lang.reflect.InvocationTargetException;
import java.util.Map;

/**
 * @Classname WebUtils
 * @Description TODO
 * @Date 2020/11/17 13:17
 * @author by 97830
 */
public class WebUtils {
    public static <T> T copyParamToBean(Map value,T bean){
        try {
            //把所有请求参数注入到user对象中
            BeanUtils.populate(bean, value);
        } catch (IllegalAccessException | InvocationTargetException e) {
            e.printStackTrace();
        }
        return bean;
    }

    public static int parseInt(String strInt,int defaultValue){
        try {
            return Integer.parseInt(strInt);
        } catch (NumberFormatException e) {
        }
        return defaultValue;
    }
}